/*
 * Cliente.java
 *
 * Created on 25 de Maio de 2007, 05:45
 *
 */

package net.sf.jOpinionPoll.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

/**
 *
 * @author erico
 */
@Entity
@Table(name="cliente")
@NamedQueries({
        @NamedQuery(name = "Cliente.findAll", query = "SELECT cliente FROM Cliente cliente"),
        @NamedQuery(name = "Cliente.count", query = "SELECT COUNT(cliente) FROM Cliente cliente")
         })
public class Cliente implements Serializable {
	private static final long serialVersionUID = 1L;
	
    private int id;
    private String nome;
    private String sobrenome;
    private Date nascimento;
    private TipoDeSexo sexo;
    private String email;
    private String cpfcnpj;
    private Endereco endereco;
    private String telefoneFixo;
    private String telefoneMovel;
    private String telefoneComercial;
    private String observacoes;
    
    public static enum TipoDeSexo {M, F};
    
    public Cliente() {
    }

    @Id
    @Column(name="id")
    @TableGenerator(
            name="clienteGen",
            table="sequence_generator_table",
            pkColumnName="gen_key",
            pkColumnValue="cliente_id",
            valueColumnName="gen_value",
            allocationSize=50,
            initialValue=0)
    @GeneratedValue(
            strategy=GenerationType.TABLE,
            generator="clienteGen")
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Column(name="nome", nullable=false)
    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    @Column(name="sobrenome")
    public String getSobrenome() {
        return sobrenome;
    }

    public void setSobrenome(String sobrenome) {
        this.sobrenome = sobrenome;
    }

    @Column(name="nascimento")
    @Temporal(value = TemporalType.TIMESTAMP)
    public Date getNascimento() {
        return nascimento;
    }

    public void setNascimento(Date nascimento) {
        this.nascimento = nascimento;
    }

    @Column(name="sexo")
    @Enumerated(EnumType.STRING) 
    public TipoDeSexo getSexo() {
        return sexo;
    }

    public void setSexo(TipoDeSexo sexo) {
        this.sexo = sexo;
    }

    @Column(name="email")
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Column(name="cpfcnpj")
    public String getCpfcnpj() {
        return cpfcnpj;
    }

    public void setCpfcnpj(String cpfcnpj) {
        this.cpfcnpj = cpfcnpj;
    }

    @OneToOne(cascade=CascadeType.ALL, fetch=FetchType.LAZY, optional=false)
    @JoinColumn(name="endereco_id")
    public Endereco getEndereco() {
        return endereco;
    }

    public void setEndereco(Endereco endereco) {
        this.endereco = endereco;
    }

    @Column(name="telefone_fixo")
    public String getTelefoneFixo() {
        return telefoneFixo;
    }

    public void setTelefoneFixo(String telefoneFixo) {
        this.telefoneFixo = telefoneFixo;
    }

    @Column(name="telefone_movel")
    public String getTelefoneMovel() {
        return telefoneMovel;
    }

    public void setTelefoneMovel(String telefoneMovel) {
        this.telefoneMovel = telefoneMovel;
    }

    @Column(name="telefone_comercial")
    public String getTelefoneComercial() {
        return telefoneComercial;
    }

    public void setTelefoneComercial(String telefoneComercial) {
        this.telefoneComercial = telefoneComercial;
    }

    @Column(name="observacoes")
    public String getObservacoes() {
        return observacoes;
    }

    public void setObservacoes(String observacoes) {
        this.observacoes = observacoes;
    }
    
    /**
     * Returns a hash code value for the object.  This implementation computes
     * a hash code value based on the id fields in this object.
     * @return a hash code value for this object.
     */
    @Override
    public int hashCode() {
        return getId();
    }
    
/**
     * Determines whether another object is equal to this Usuario.  The result is
     * <code>true</code> if and only if the argument is not null and is a Usuario object that
     * has the same id field values as this object.
     * @param o the reference object with which to compare
     * @return <code>true</code> if this object is the same as the argument;
     * <code>false</code> otherwise.
     */
    @Override
    public boolean equals(Object o) {
    	if (o == null || !(o instanceof Cliente))
            return false;

        if (getId() != 0)
	        return (getId() == ((Cliente)o).getId());
        
        return this == o;
    }
    
    /**
     * Returns a string representation of the object.  This implementation constructs
     * that representation based on the id fields.
     * @return a string representation of the object.
     */
    @Override
    public String toString() {
        return this.getClass().getName() + "[pk=" + getId() + "]";
    }
}